import {
  TonTplGroupGateway,
  TonTplGroup,
  putTonTplGroupDto,
  PageResult,
  TonTplGroupInterfaceWithPrimary,
  deleteTonTplGroupDto,
  PutMutiRes,
  DisableRes,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { TonTplGroupSchema } from "@/river/ton-tpl";

export class ViewTonTplGroup extends ViewBase<TonTplGroup> implements ViewBaseAction<TonTplGroup>, TonTplGroupInterfaceWithPrimary<{}> {
  private static instance: ViewTonTplGroup;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewTonTplGroup();
    }

    if (!this.instance) this.instance = new ViewTonTplGroup();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  getSchema(): TonTplGroup {
    return new TonTplGroupSchema();
  }

  async get() {
    this.pending();
    return this.$request.get<null, PageResult<TonTplGroup>>(TonTplGroupGateway.path);
  }

  async put() {
    this.pending();
    const dto = { schemaList: this.data.schemaList };
    return this.$request.put<putTonTplGroupDto, PutMutiRes<TonTplGroup>>(TonTplGroupGateway.path, dto);
  }

  async disable(dto: deleteTonTplGroupDto) {
    this.pending();
    return this.$request.delete<deleteTonTplGroupDto, DisableRes>(TonTplGroupGateway.path, dto);
  }
}
